package com.lky.project.controller;

import com.lky.project.mapper.OrderMapper;
import com.lky.project.mapper.PjMapper;
import com.lky.project.pojo.Order;
import com.lky.project.pojo.Pj;
import com.lky.project.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author: 张
 * @time： 2023 - 04 - 30 - 17:20:55
 */
@RestController
@CrossOrigin
@RequestMapping("pj")
public class PjController {

    @Autowired
    private PjMapper pjMapper;

    @Autowired
    private OrderMapper orderMapper;

    @RequestMapping("/add")
    public Result addPj(Pj pj){
        Order order = new Order();
        order.setOid(pj.getOId());
        order.setIsPj(1);
        orderMapper.updateById(order);
        pjMapper.insert(pj);
        return Result.ok();
    }

    @RequestMapping("/list")
    public Result pjList(String sid){

        List<Map> pjBySid = pjMapper.getPjBySid(sid);
        return Result.ok(pjBySid);
    }
}
